package com.xjtu.controller.admin;

import com.xjtu.entity.Assessment;
import com.xjtu.entity.CapabilityAssessment;
import com.xjtu.entity.Elderly;
import com.xjtu.mapper.ElderlyMapper;
import com.xjtu.result.PageResult;
import com.xjtu.result.Result;
import com.xjtu.service.BaseInfoService;
import com.xjtu.service.ElderlyService;
import com.xjtu.vo.baseInfo.AssessmentTableVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import java.util.List;

@RestController
@RequestMapping("/admin/baseinfo")
@Slf4j
@Api(tags = "管理员端老人基本信息")
public class BaseInfoController {
    @Autowired(required = false)
    private ElderlyService elderlyService;

    @Autowired
    private BaseInfoService baseInfoService;

    @GetMapping("/{id}")
    @ApiOperation("根据id获取老人基本信息")
    private Result<Elderly> queryById(@PathVariable @Min(value = 1,message = "参数错误") Integer id){
        Elderly elderly = elderlyService.queryById(id);
        return Result.success(elderly);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询老人基本信息")
    private Result<PageResult> getElderlyLists(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                  @RequestParam(required = false, defaultValue = "10")Integer size,
                                                  @RequestParam(required = false, defaultValue = "") String name){
        PageResult resp = elderlyService.pageQuery(page,size,name);
        return Result.success(resp);
    }

    @GetMapping("/assessment/{id}")
    @ApiOperation("根据能力评估表的id获取对应的详细信息")
    public Result<AssessmentTableVo> queryAssessmentTableById(@PathVariable @Min(value = 1,message = " 参数异常") Integer id){
        AssessmentTableVo resp = baseInfoService.queryAssessmentTableById(id);
        return Result.success(resp);
    }

    @GetMapping("/assessment")
    @ApiOperation("通过老人id查看某个老人所有的能力评估表记录")
    private Result<List<CapabilityAssessment>> AssessmentTableListsByEldelyId(@RequestParam @Min(value = 1,message = "参数错误")Integer elderlyId){
        List<CapabilityAssessment> resp = baseInfoService.queryAssessmentTableListsByElderlyId(elderlyId);
        return Result.success(resp);
    }

    @GetMapping("/assesspage")
    @ApiOperation("分页查询所有评估表")
    public Result<PageResult> pageQueryAssessmentTable(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                  @RequestParam(required = false, defaultValue = "10")Integer size,
                                                  @RequestParam(required = false, defaultValue = "") String name){
        PageResult resp = baseInfoService.pageQuery(page,size,name);
        return Result.success(resp);
    }

    @GetMapping("/assessreport")
    @ApiOperation("分页查询所有评估报告")
    public Result<PageResult> pageQueryAssessmentReport(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                  @RequestParam(required = false, defaultValue = "10")Integer size,
                                                  @RequestParam(required = false, defaultValue = "") String name){
        PageResult resp = baseInfoService.pageQueryAssessmentReport(page,size,name);
        return Result.success(resp);
    }
}
